class NormalStuff {
  protected readonly OFFSET_SELL_IN = 1;
  protected readonly EXPIRATION_SELL_IN = 0;

  protected readonly OFFSET_QUALITY_ONE = 1;
  protected readonly OFFSET_QUALITY_TWO = 2;
  protected readonly OFFSET_QUALITY_THREE = 3;

  protected readonly MIN_QUALITY = 0;
  protected readonly MAX_QUALITY = 50;

  constructor(protected sellIn: number, protected quality: number) {}

  protected isExpiration(sellIn: number): boolean {
    return sellIn < this.EXPIRATION_SELL_IN;
  }

  protected cleanQuality(quality: number): number {
    return Math.max(this.MIN_QUALITY, Math.min(this.MAX_QUALITY, quality));
  }

  setSellIn(sellIn: number): BaseStuff {
    this.sellIn = sellIn;
    return this;
  }

  setQuality(quality: number): BaseStuff {
    this.quality = quality;
    return this;
  }

  updateSellIn(): number {
    return this.sellIn = this.sellIn - this.OFFSET_SELL_IN;
  }

  updateQuality(): number {
    const isExpired = this.isExpiration(this.sellIn);
    return this.quality = this.cleanQuality(
      this.quality -
        (isExpired ? this.OFFSET_QUALITY_TWO : this.OFFSET_QUALITY_ONE)
    );
  }

  tomorrow(): [number, number] {
    return [this.updateSellIn(), this.updateQuality()];
  }
}

export default NormalStuff;
